package algorithm.子集;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

class Solution {

    List<Integer> t = new ArrayList<Integer>();
    List<List<Integer>> ans = new ArrayList<List<Integer>>();

    public static void main(String[] args) {
        int [] arr=new int[]{1,2,3,4};
        Solution solution=new Solution();
        List<List<Integer>> rs=solution.subsets(arr);
        rs.forEach(list->System.out.println(StringUtils.join(list,",")));
    }

    public List<List<Integer>> subsets(int[] nums) {
        dfs(0, nums);
        return ans;
    }

    public void dfs(int cur, int[] nums) {
        if (cur == nums.length) {
            ans.add(new ArrayList<Integer>(t));
            return;
        }
        t.add(nums[cur]);
        dfs(cur + 1, nums);
        t.remove(t.size() - 1);
        dfs(cur + 1, nums);
    }
}

//作者：LeetCode-Solution
//链接：https://leetcode.cn/problems/subsets/solution/zi-ji-by-leetcode-solution/
//来源：力扣（LeetCode）
//著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。